package org.flowers.unbeaten.util;


/**
 * @description ID生成器
 * @author RyanWang
 * @date 2021-07-19 16:10:15
 * @version 1.0
 */
public final class Id {

    /**循环次数**/
    private static int loopCount = 0;

    private static Object lock = new Object();

    private static String[] arr = {"", "0", "00", "000", "0000", "00000", "000000"};

    /**
     * 生成ID
     * @return
     */
    public static String generateId() {
        long t = System.currentTimeMillis() / 10;
        return Long.toString(t) + getSuffix();
    }

    private static String getSuffix() {
        String suffix = null;
        synchronized (lock) {
            ++loopCount;
            if (loopCount == 1000000) {
                loopCount = 1;
            }
            suffix = "" + loopCount;
        }
        return arr[6 - suffix.length()] + suffix;
    }

}
